import { MessageBox } from 'element-ui';
import { message } from '@/utils/util';

export default {
  name: 'script-settings-list-table',
  props: {
    data: {
      type: Array,
      default: () => [],
    },
    total: {
      type: Number,
      default: 0,
    },
    pageNum: {
      type: Number,
      default: 1,
    },
    pageSize: {
      type: Number,
      default: 10,
    },
    loading: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    currentPage() {
      return this.pageNum;
    },
  },
  data() {
    return {};
  },
  methods: {
    onPageSizeChange(pageSize) {
      this.$emit('pageSizeChange', pageSize);
    },
    onPageNumChange(pageNum) {
      this.$emit('pageNumChange', pageNum);
    },
    onOpenDetailModal(row) {
      this.$emit('onOpenEditModal', row);
    },
    onEnable(row) {
      MessageBox.confirm('确定启用脚本？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.$emit('onEnable', row.id);
        })
        .catch(() => {
          message('提示', '已取消操作', 'warning');
        });
    },
    onDisable(row) {
      MessageBox.confirm('确定禁用脚本？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.$emit('onDisable', row.id);
        })
        .catch(() => {
          message('提示', '已取消操作', 'warning');
        });
    },
  },
  mounted() {},
};
